﻿package bacIns.exchangeddata 
{
	/**
	 * ...
	 * @author Doan Nguyen Thuy Nha Truc (Bamboo)
	 */
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import game.constants.ConstData
	import game.events.EventData;
	import common.Utility;
	public class BacHistoryInfo extends EventDispatcher
	{
		
		public var history:Array;
		public var odlResult:String;// check call showresult that is loops 
		public var vodId:String;
		
		public var historyNum:Array;
		public function BacHistoryInfo() 
		{
			history = new Array();	
			historyNum = new Array();
			vodId = "";
		}
		/**
		 * @author Bamboo
		 * @param	result: is array history 
		 */
		public function setHistory(result:Array, resultNum:Array):void {
			history = result;
			historyNum = resultNum;
			//trace("history daisy" + history);
			dispatchEvent(new Event(EventData.UPDATE_HISTORY));
		}
		
		/**
		 * @author Bamboo
		 * @param	result : value that return by fms
		 * @return array history
		 */
		public function returnSetHistory(result:String):Array{
			odlResult = result;
			var resultArr:Array = new Array();
					
			var numberHistory:int =  int(result.substr(ConstData.POS_HIS_RESULT, ConstData.LEN_NUM_HIS));
			var resultStr:String = result.substr((ConstData.POS_HIS_RESULT + ConstData.LEN_NUM_HIS) , (ConstData.LEN_VALUE_HIS * numberHistory));
						
			while(resultStr.length >= 2) {
				resultArr.push(resultStr.slice(0, 2));
				resultStr = resultStr.slice(2, resultStr.length);
			}			
			
			return resultArr;
		}
		/**
		 * @author	Bamboo
		 * @param	result
		 */
		public function returnVodId(result:String):void {
			var tempStr:String = result.substr(1, result.length);
			var tempArr:Array = tempStr.split("_");
			for (var i:int = 0; i < tempArr.length; i++)
				this.vodId += tempArr[i] + "_";			
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 */
		public function returnSetHistoryNum(result:String):Array {
			var arr:Array = result.split("&");
			var strHistory:String = arr[arr.length - 1];
			var resultArr:Array = new Array();
			for (var i = 0; i < strHistory.length; i++) {
				resultArr.push(strHistory.substr(i,1));
			}	
			return resultArr;
		}
	}

}